from socket import *
import time

HOST = '127.0.0.1'
PORT = 8888
BUFSIZ = 1024
ADDRESS = (HOST, PORT)

udpClientSocket = socket(AF_INET, SOCK_DGRAM)
N = 100
t0 = time.time()
for i in range(100):
    data = "1+2"
    if not data:
        break

    # 发送数据
    udpClientSocket.sendto(data.encode('utf-8'), ADDRESS)
    # 接收数据
    data, ADDR = udpClientSocket.recvfrom(BUFSIZ)
    if not data:
        break
    # print("服务器端响应：", data.decode('utf-8'))
t1 = time.time()
print(t1-t0, (t1-t0)/N)
udpClientSocket.close()
